<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

function navtab_active($name = null)
{
	$ci =& get_instance();
	
	if($name == $ci->uri->segment(1))
		echo ' class="active"';
	elseif($ci->uri->uri_string() == FALSE && $name == NULL)
		echo ' class="active"';
}

function crud_flash_and_redirect($type, $redirect = FALSE)
{
	$ci =& get_instance();
	
	if($type == 'add')
	{
		$alert = 'success';
		$msg = '<strong>Entry created!</strong> You have successfully created a new entry.';
	}
	elseif($type == 'edit')
	{
		$alert = 'info';
		$msg = '<strong>Entry Updated!</strong> You have successfully updated an existing entry.';
	}
	elseif($type == 'delete')
	{
		$alert = 'error';
		$msg = '<strong>Entry deleted!</strong> You have successfully deleted an existing entry.';
	}
	
	$flash = array(
		'alert' => $alert,
		'message' => $msg
	);
	
	$ci->session->set_flashdata('alert', $flash);
	if($redirect)
	{
		$uri_to_redirect = $redirect;
	}
	else
	{
		$uri_to_redirect = $ci->uri->segment(1);
	}

	redirect($uri_to_redirect);
}

function flash_notification()
{
	$ci =& get_instance();
	
	if($ci->session->flashdata('alert'))
	{
		$data['flash'] = $ci->session->flashdata('alert');
		$ci->load->view('includes/notification', $data);
	}
}

function my_form_input($name, $value, $size, $type = FALSE, $note = FALSE, $textarea_rows = 4) 
{
	/*
	$data_sample = array(
		'field_name' => '',
		'name' => '',
		'value' => '',
		'size' => '',
		'type' => '',
		'note' =>
	);
	*/
	
	$ci =& get_instance();
	
	$data['name'] = $name;
	$data['value'] = $value;
	$data['size'] = $size;
	$data['type'] = $type;
	$data['note'] = $note;
	$data['rows'] = $textarea_rows;
	$ci->load->view('includes/_form_input', $data);
}

function task_status($status)
{
	$sta = "";
	$sty = "";
	switch ($status) 
	{
		case 1:
			$sta = "Done";
			$sty = "";
			break;
		
		case 2:
			$sta = "In Progress";
			$sty = "notice";
			break;
		
		case 3:
			$sta = "Urgent";
			$sty = "important";
			break;
		
		case 4:
			$sta = "important";
			$sty = "warning";
			break;
		
		default:	
			$sta = "";
			$sty = "";
			break;
	}

	$text = '<span class="label '.$sty.'">'.$sta.'</span>';

	return $text;
}

function mpr($d, $echo = TRUE)
{
        if($echo)
        {
                echo '<pre>'.print_r($d, true).'</pre>';
        }
        else
        {
                return '<pre>'.print_r($d, true).'</pre>';
        } 
}

function mprd($d) 
{ 	
        mpr($d); 	
        die; 
}

function mvr($d) 	
{
        echo '<pre>'.var_dump($d, true).'</pre>'; 
}

function mvrd($d) 
{
        mvr($d);
        die; 
}

function dlog($message)
{
	// $message - the message to log
	// $render  - whether or not to render the message to the page

	$trace = debug_backtrace(); // create a stacktrace

	$file = $trace[0]['file']; // file that called dlog
	$line = $trace[0]['line']; // line in file that called dlog
	$function = $trace[1]['function']; // function that called dlog

	// logname will be the same as the calling file plus '.log'
	$filename = implode('/', array_slice(explode('/', $file), -1));

	// the rest logs the message
	$msg = date('Y-m-d H:i:s').' | '.$function." (".$filename.":".$line.") : ".print_r($message, TRUE)."\n";

	$fobj = fopen('./debug.log', 'a+');
	fwrite($fobj, $msg);
}

/* End of file alix_helper.php */